package com.tbit.uqbike.webmanager.controller;

import com.github.pagehelper.PageInfo;
import com.tbit.uqbike.object.pojo.MachineFeeBound;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.MachineFeeBoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备计费规则绑定Controller
 *
 * @author jing
 * @date 2021-06-01
 */
@RestController
@RequestMapping("/bound")
public class MachineFeeBoundController extends BaseController {
    @Autowired
    private MachineFeeBoundService machineFeeBoundService;

    /**
     * 查询设备计费规则绑定列表
     */
    @GetMapping("/list")
    public JsonResult list(MachineFeeBound machineFeeBound) {
        startPage();
        List<MachineFeeBound> list = machineFeeBoundService.selectMachineFeeBoundList(machineFeeBound);
        return JsonResult.ok(list, (int) new PageInfo<>(list).getTotal());
    }


    /**
     * 新增设备计费规则绑定
     */
    @PostMapping
    public JsonResult add(@RequestBody MachineFeeBound machineFeeBound) {
        return JsonResult.ok(machineFeeBoundService.insertMachineFeeBound(machineFeeBound));
    }

    /**
     * 删除设备计费规则绑定
     */
    @DeleteMapping
    public JsonResult remove(MachineFeeBound machineFeeBound) {
        return JsonResult.ok(machineFeeBoundService.deleteMachineFeeBoundByIds(machineFeeBound));
    }
}
